const crypto = require("crypto");
const secret = Buffer.from("mfoq7bkkrby2ndrr");
const iv = Buffer.from("fckxrg5h66w3wrk6")

module.exports = {
    // 提供一个加密算法
    encrypto(str){
        // 得到所有的加密方法
    //    crypto.getCiphers()
        // 创建一个加密方法
        const fn = crypto.createCipheriv('aes-128-cbc',secret,iv)
        let result = fn.update(str,"utf-8","hex")
        result += fn.final("hex")
        return result
    },
    // b18435296de2939c2a8d4e976b8f5c1d
    // 提供一个解密算法
    decrypto(str){
        const fn = crypto.createDecipheriv('aes-128-cbc',secret,iv)
        let result = fn.update(str,"hex","utf-8");
        result+=fn.final("utf-8");
        return result
    },

}

// module.exports.decrypto('b18435296de2939c2a8d4e976b8f5c1d')